package org.jeecg.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.entity.DbIndustry;
import org.jeecg.modules.entity.DbStation;
import org.jeecg.modules.mapper.DbStationMapper;
import org.jeecg.modules.service.IDbStationService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description: db_station
 * @Author: jeecg-boot
 * @Date:   2024-07-08
 * @Version: V1.0
 */
@Service
public class DbStationServiceImpl extends ServiceImpl<DbStationMapper, DbStation> implements IDbStationService {
    /**
     * 部门岗位联级差询
     * @return
     */
    public List<DbStation> listDepartAndStation() {
        List<DbStation> json=this.list(new QueryWrapper<DbStation>().isNull("parent_id"));
        if(json.isEmpty()){
            return json;
        }
        List list = new ArrayList<>();
        json.forEach(item->{
            list.add(item.getId());
        });
        List<DbStation> json2 = this.list(new QueryWrapper<DbStation>().in("parent_id", list));
        Map<String,List<DbStation>> mdv=json2.stream().collect(Collectors.groupingBy(DbStation::getParentId));
        json.stream().forEach(item->item.setChildren(mdv.get(item.getId())));
        return json;
    }

}
